package cn.shop.dys.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.LinearLayout;

/**
 * 主界面控件
 * Created by sunjian on 2016/4/8.
 */
public class MainContenLinearLayout extends LinearLayout{
    private  GestureDetector.OnGestureListener mGestrueListener=new GestureDetector.SimpleOnGestureListener(){
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            if(listener!=null){
                listener.close();
            }
            return super.onSingleTapUp(e);
        }
    };
    private OnMenuStatusChangeListener listener;
    private GestureDetector gestureDetector;

    public MainContenLinearLayout(Context context) {
        this(context, null);
    }

    public MainContenLinearLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MainContenLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        gestureDetector = new GestureDetector(context, mGestrueListener);
    }
    public void setOnMenuStatusChangeListener(OnMenuStatusChangeListener listener){
        this.listener=listener;
    }
    public interface OnMenuStatusChangeListener{
        boolean isOpen();
        void close();
    }
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if(listener!=null){
            return listener.isOpen();
        }
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        gestureDetector.onTouchEvent(event);
        return true;
    }
}
